﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RooHui.Infrastructure.Entities.EntityCache;
using RooHui.Infrastructure.Entities.Entity;
namespace RooHui.Infrastructure.Entities.EntityCode
{
    /// <summary>
    /// 参数只包含一个，为用户名
    /// </summary>
    public class AccountCache : EntitiesCache<Account>
    {
        /// <summary>
        /// key 为 username
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public override Account GetItem(params string[] keys)
        {
            return base.GetItem(keys);
        }
        protected override bool ValidateParameter(params string[] keys)
        {
            return keys.Length == 1 && !String.IsNullOrEmpty(keys[0]);
        }
        protected override Account LoadDataItem(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                string username = keys[0];
                var member = new Account().Find(c => c.UserName == username);
                return member;
            }
            return null;
        }
        protected override string BuildKey(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                return String.Format("GetMemberEntity_{0}", keys[0]);
            }
            return string.Empty;
        }
        protected override string BuildKey(Account data)
        {
            if (data != null && !String.IsNullOrEmpty(data.UserName))
            {
                return BuildKey(data.UserName);
            }
            return string.Empty;
        }

    }
}
